from new_test_framework.utils import tdLog, tdSql, tdCom
import random

import time
import socket
import os
import threading

from datetime import timezone, datetime


class TestPrimaryTsBase:
    hostname = socket.gethostname()

    def setup_class(cls):
        cls.replicaVar = 1  # 设置默认副本数
        tdLog.debug(f"start to excute {__file__}")
        #tdSql.init(conn.cursor(), logSql)
    def case_init(self):
        self.database = 'primary_db'
        self.testcasePath = os.path.split(__file__)[0]
        self.testcaseFilename = os.path.split(__file__)[-1]
        os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename))

    def dropandcreateDB_primary_key(self,database,once_insert_num,updata_num=1,dropdb='yes',insertdata='yes',deletedata='yes'): #fixed
        tdSql.query("alter local 'schedulePolicy' '%d';" %random.randint(1,3))
        self.ts = 1630000000000
        
        if dropdb == 'yes':
            tdSql.execute('''create database %s VGROUPS %d;'''%(database,random.randint(1,10)))
            tdSql.execute('''use %s;'''%database)
        
            #stable
            tdSql.execute(f'''create stable {database}.stable_0 (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint ,q_int_unsigned int unsigned, q_bigint_unsigned bigint unsigned, q_smallint_unsigned smallint unsigned, q_tinyint_unsigned tinyint unsigned, q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
                q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \
                tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_int_unsigned int unsigned, t_bigint_unsigned bigint unsigned, t_smallint_unsigned smallint unsigned, t_tinyint_unsigned tinyint unsigned, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''')
            tdSql.execute(f'''create stable {database}.stable_1 (ts timestamp , ts_pk INT primary key, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint ,q_int_unsigned int unsigned, q_bigint_unsigned bigint unsigned, q_smallint_unsigned smallint unsigned, q_tinyint_unsigned tinyint unsigned, q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
                q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \
                tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_int_unsigned int unsigned, t_bigint_unsigned bigint unsigned, t_smallint_unsigned smallint unsigned, t_tinyint_unsigned tinyint unsigned, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''')
            tdSql.execute(f'''create stable {database}.stable_2 (ts timestamp , ts_pk INT UNSIGNED primary key, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint ,q_int_unsigned int unsigned, q_bigint_unsigned bigint unsigned, q_smallint_unsigned smallint unsigned, q_tinyint_unsigned tinyint unsigned, q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
                q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \
                tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_int_unsigned int unsigned, t_bigint_unsigned bigint unsigned, t_smallint_unsigned smallint unsigned, t_tinyint_unsigned tinyint unsigned,  t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''')
            tdSql.execute(f'''create stable {database}.stable_3 (ts timestamp , ts_pk BIGINT primary key, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint ,q_int_unsigned int unsigned, q_bigint_unsigned bigint unsigned, q_smallint_unsigned smallint unsigned, q_tinyint_unsigned tinyint unsigned, q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
                q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \
                tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_int_unsigned int unsigned, t_bigint_unsigned bigint unsigned, t_smallint_unsigned smallint unsigned, t_tinyint_unsigned tinyint unsigned,  t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''')
            tdSql.execute(f'''create stable {database}.stable_4 (ts timestamp , ts_pk BIGINT UNSIGNED primary key, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint ,q_int_unsigned int unsigned, q_bigint_unsigned bigint unsigned, q_smallint_unsigned smallint unsigned, q_tinyint_unsigned tinyint unsigned, q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
                q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \
                tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_int_unsigned int unsigned, t_bigint_unsigned bigint unsigned, t_smallint_unsigned smallint unsigned, t_tinyint_unsigned tinyint unsigned,  t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''')
            tdSql.execute(f'''create stable {database}.stable_5 (ts timestamp , ts_pk VARCHAR(100) primary key, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint ,q_int_unsigned int unsigned, q_bigint_unsigned bigint unsigned, q_smallint_unsigned smallint unsigned, q_tinyint_unsigned tinyint unsigned, q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
                q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \
                tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_int_unsigned int unsigned, t_bigint_unsigned bigint unsigned, t_smallint_unsigned smallint unsigned, t_tinyint_unsigned tinyint unsigned,  t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''')
            tdSql.execute(f'''create stable {database}.stable_6 (ts timestamp , ts_pk BINARY(100) primary key, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint ,q_int_unsigned int unsigned, q_bigint_unsigned bigint unsigned, q_smallint_unsigned smallint unsigned, q_tinyint_unsigned tinyint unsigned, q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
                q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \
                tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_int_unsigned int unsigned, t_bigint_unsigned bigint unsigned, t_smallint_unsigned smallint unsigned, t_tinyint_unsigned tinyint unsigned,  t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''')
            
            #regular table
            tdSql.execute(f'''create table {database}.regular_table_0 \
                    (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint ,q_int_unsigned int unsigned, q_bigint_unsigned bigint unsigned, q_smallint_unsigned smallint unsigned, q_tinyint_unsigned tinyint unsigned, q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
                    q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''')
            tdSql.execute(f'''create table {database}.regular_table_1 \
                    (ts timestamp , ts_pk INT primary key, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint ,q_int_unsigned int unsigned, q_bigint_unsigned bigint unsigned, q_smallint_unsigned smallint unsigned, q_tinyint_unsigned tinyint unsigned, q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
                    q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''')
            tdSql.execute(f'''create table {database}.regular_table_2 \
                    (ts timestamp , ts_pk INT UNSIGNED primary key, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint ,q_int_unsigned int unsigned, q_bigint_unsigned bigint unsigned, q_smallint_unsigned smallint unsigned, q_tinyint_unsigned tinyint unsigned, q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
                    q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''')
            tdSql.execute(f'''create table {database}.regular_table_3 \
                    (ts timestamp , ts_pk BIGINT primary key, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint ,q_int_unsigned int unsigned, q_bigint_unsigned bigint unsigned, q_smallint_unsigned smallint unsigned, q_tinyint_unsigned tinyint unsigned, q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
                    q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''')

            tdSql.execute(f'''create table {database}.regular_table_4 \
                    (ts timestamp , ts_pk BIGINT UNSIGNED primary key, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint ,q_int_unsigned int unsigned, q_bigint_unsigned bigint unsigned, q_smallint_unsigned smallint unsigned, q_tinyint_unsigned tinyint unsigned, q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
                    q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''')
            tdSql.execute(f'''create table {database}.regular_table_5 \
                    (ts timestamp , ts_pk VARCHAR(100) primary key, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint ,q_int_unsigned int unsigned, q_bigint_unsigned bigint unsigned, q_smallint_unsigned smallint unsigned, q_tinyint_unsigned tinyint unsigned, q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
                    q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''')
            tdSql.execute(f'''create table {database}.regular_table_6 \
                    (ts timestamp , ts_pk BINARY(100) primary key, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint ,q_int_unsigned int unsigned, q_bigint_unsigned bigint unsigned, q_smallint_unsigned smallint unsigned, q_tinyint_unsigned tinyint unsigned, q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
                    q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''')

            #child table
            for tag_i in range(1,11):
                tdSql.execute(f'''create table {database}.stable_0_{tag_i} using {database}.stable_0 tags('stable_0_{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}' , 0 , 'binary1.{tag_i}' , 'nchar1.{tag_i}' , '{tag_i}', '{tag_i}' ,'{tag_i}') ;''' )
                tdSql.execute(f'''create table {database}.stable_1_{tag_i} using {database}.stable_1 tags('stable_1_{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}' , 0 , 'binary1.{tag_i}' , 'nchar1.{tag_i}' , '{tag_i}', '{tag_i}' ,'{tag_i}') ;''' )
                tdSql.execute(f'''create table {database}.stable_2_{tag_i} using {database}.stable_2 tags('stable_2_{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}' , 1 , 'binary2.{tag_i}' , 'nchar2.{tag_i}' , '{tag_i}', '{tag_i}' ,'{tag_i}') ;''' )
                tdSql.execute(f'''create table {database}.stable_3_{tag_i} using {database}.stable_3 tags('stable_3_{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}' , 0 , 'binary3.{tag_i}' , 'nchar3.{tag_i}' , '{tag_i}', '{tag_i}' ,'{tag_i}') ;''' )
                tdSql.execute(f'''create table {database}.stable_4_{tag_i} using {database}.stable_4 tags('stable_4_{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}' , 1 , 'binary4.{tag_i}' , 'nchar4.{tag_i}' , '{tag_i}', '{tag_i}' ,'{tag_i}') ;''' )
                tdSql.execute(f'''create table {database}.stable_5_{tag_i} using {database}.stable_5 tags('stable_5_{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}' , 0 , 'binary5.{tag_i}' , 'nchar5.{tag_i}' , '{tag_i}', '{tag_i}' ,'{tag_i}') ;''' )
                tdSql.execute(f'''create table {database}.stable_6_{tag_i} using {database}.stable_6 tags('stable_6_{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}', '{tag_i}' , '{tag_i}' , 1 , 'binary6.{tag_i}' , 'nchar6.{tag_i}' , '{tag_i}', '{tag_i}' ,'{tag_i}') ;''' )

        else:
            tdSql.execute('''use %s;'''%database)

        if insertdata == 'yes':            
            for tag_i in range(1,11):
                for column_i in range(41,51):    
                    tdSql.execute(f'''insert into {database}.stable_0_{tag_i}  (ts , q_int , q_bigint , q_smallint , q_tinyint ,q_int_unsigned , q_bigint_unsigned , q_smallint_unsigned , q_tinyint_unsigned , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values('{self.ts + 100000000}',  '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + column_i*100000000 + 1 }',  '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + 2000000000 - 1000000000 + 2 }', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}')  
                            {database}.stable_0_{tag_i}  (ts) values('{self.ts + 100000000 + 10 }') ('{self.ts + column_i*100000000 + 11 }') ('{self.ts + 2000000000 - 1000000000 + 12 }') 
                    
                            {database}.stable_1_{tag_i}  (ts , ts_pk , q_int , q_bigint , q_smallint , q_tinyint ,q_int_unsigned , q_bigint_unsigned , q_smallint_unsigned , q_tinyint_unsigned , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values('{self.ts + 100000000}', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + column_i*100000000 + 1 }', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + 2000000000 - 1000000000 + 2 }', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}')
                            {database}.stable_1_{tag_i}  (ts , ts_pk ) values('{self.ts + 100000000 + 10 }', '{column_i - 25}') ('{self.ts + column_i*100000000 + 11 }', '{column_i - 25}') ('{self.ts + 2000000000 - 1000000000 + 12 }', '{column_i - 25}')  
                    
                            {database}.stable_2_{tag_i}  (ts , ts_pk , q_int , q_bigint , q_smallint , q_tinyint ,q_int_unsigned , q_bigint_unsigned , q_smallint_unsigned , q_tinyint_unsigned , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values('{self.ts + 100000000}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + column_i*200000000 + 2 }', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + 1000000000 + 1 }', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            {database}.stable_2_{tag_i}  (ts , ts_pk ) values('{self.ts + 100000000 + 10 }', '{column_i}') ('{self.ts + column_i*200000000 + 12 }', '{column_i}') ('{self.ts + 1000000000 + 11 }', '{column_i}') 
                    
                            {database}.stable_3_{tag_i}  (ts , ts_pk , q_int , q_bigint , q_smallint , q_tinyint ,q_int_unsigned , q_bigint_unsigned , q_smallint_unsigned , q_tinyint_unsigned , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values('{self.ts + 100000000}', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + column_i*300000000 + 3 }', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}')
                            ('{self.ts + 10000000000 + 1 }', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            {database}.stable_3_{tag_i}  (ts , ts_pk ) values('{self.ts + 100000000 + 10 }', '{column_i - 25}') ('{self.ts + column_i*300000000 + 13 }', '{column_i - 25}') ('{self.ts + 10000000000 + 11 }', '{column_i - 25}') 
                    
                            {database}.stable_4_{tag_i}  (ts , ts_pk , q_int , q_bigint , q_smallint , q_tinyint ,q_int_unsigned , q_bigint_unsigned , q_smallint_unsigned , q_tinyint_unsigned , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values('{self.ts + 100000000}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + column_i*400000000 + 4 }', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + 100000000000 + 1 }', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            {database}.stable_4_{tag_i}  (ts , ts_pk ) values('{self.ts + 100000000 + 10 }', '{column_i}') ('{self.ts + column_i*400000000 + 14 }', '{column_i}') ('{self.ts + 100000000000 + 11 }', '{column_i}') 
                    
                            {database}.stable_5_{tag_i}  (ts , ts_pk , q_int , q_bigint , q_smallint , q_tinyint ,q_int_unsigned , q_bigint_unsigned , q_smallint_unsigned , q_tinyint_unsigned , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values('{self.ts + 100000000}', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + column_i*500000000 + 5 }', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + 1000000000000 + 1 }', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}')
                            {database}.stable_5_{tag_i}  (ts , ts_pk ) values('{self.ts + 100000000 + 10 }', '{column_i - 25}') ('{self.ts + column_i*500000000 + 15 }', '{column_i - 25}') ('{self.ts + 1000000000000 + 11 }', '{column_i - 25}') 
                    
                            {database}.stable_6_{tag_i}  (ts , ts_pk , q_int , q_bigint , q_smallint , q_tinyint ,q_int_unsigned , q_bigint_unsigned , q_smallint_unsigned , q_tinyint_unsigned , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values('{self.ts + 100000000}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + column_i*600000000 + 6 }', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + 10000000000000 + 1 }', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            {database}.stable_6_{tag_i}  (ts , ts_pk ) values('{self.ts + 100000000 + 10 }', '{column_i}') ('{self.ts + column_i*600000000 + 16 }', '{column_i}') ('{self.ts + 10000000000000 + 11 }', '{column_i}') ;''' ) 
                
            for column_i in range(41,51):    
                tdSql.execute(f'''insert into {database}.regular_table_0  (ts , q_int , q_bigint , q_smallint , q_tinyint ,q_int_unsigned , q_bigint_unsigned , q_smallint_unsigned , q_tinyint_unsigned , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values('{self.ts + 100000000}',  '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}')
                            ('{self.ts + column_i*100000000 + 1 }',  '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + 2000000000 - 1000000000 + 2 }', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}')
                            {database}.regular_table_0  (ts) values('{self.ts + 100000000 + 10 }') ('{self.ts + column_i*100000000 + 11 }') ('{self.ts + 2000000000 - 1000000000 + 12 }') 
                    
                            {database}.regular_table_1  (ts , ts_pk , q_int , q_bigint , q_smallint , q_tinyint ,q_int_unsigned , q_bigint_unsigned , q_smallint_unsigned , q_tinyint_unsigned , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values('{self.ts + 100000000}', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + column_i*100000000 + 1 }', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + 2000000000 - 1000000000 + 2 }', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}')
                            {database}.regular_table_1  (ts , ts_pk ) values('{self.ts + 100000000 + 10 }', '{column_i - 25}')('{self.ts + column_i*100000000 + 11 }', '{column_i - 25}') ('{self.ts + 2000000000 - 1000000000 + 12 }', '{column_i - 25}')  
                
                            {database}.regular_table_2  (ts , ts_pk , q_int , q_bigint , q_smallint , q_tinyint ,q_int_unsigned , q_bigint_unsigned , q_smallint_unsigned , q_tinyint_unsigned , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values('{self.ts + 100000000}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}')
                            ('{self.ts + column_i*200000000 + 2 }', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + 1000000000 + 1 }', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            {database}.regular_table_2  (ts , ts_pk ) values('{self.ts + 100000000 + 10 }', '{column_i}') ('{self.ts + column_i*200000000 + 12 }', '{column_i}') ('{self.ts + 1000000000 + 11 }', '{column_i}')
                
                            {database}.regular_table_3  (ts , ts_pk , q_int , q_bigint , q_smallint , q_tinyint ,q_int_unsigned , q_bigint_unsigned , q_smallint_unsigned , q_tinyint_unsigned , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values('{self.ts + 100000000}', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + column_i*300000000 + 3 }', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}')
                            ('{self.ts + 10000000000 + 1 }', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}')
                            {database}.regular_table_3  (ts , ts_pk ) values('{self.ts + 100000000 + 10 }', '{column_i - 25}') ('{self.ts + column_i*300000000 + 13 }', '{column_i - 25}') ('{self.ts + 10000000000 + 11 }', '{column_i - 25}') 
                
                            {database}.regular_table_4  (ts , ts_pk , q_int , q_bigint , q_smallint , q_tinyint ,q_int_unsigned , q_bigint_unsigned , q_smallint_unsigned , q_tinyint_unsigned , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values('{self.ts + 100000000}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}')
                            ('{self.ts + column_i*400000000 + 4 }', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + 100000000000 + 1 }', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}')
                            {database}.regular_table_4  (ts , ts_pk ) values('{self.ts + 100000000 + 10 }', '{column_i}') ('{self.ts + column_i*400000000 + 14 }', '{column_i}') ('{self.ts + 100000000000 + 11 }', '{column_i}')
                
                            {database}.regular_table_5  (ts , ts_pk , q_int , q_bigint , q_smallint , q_tinyint ,q_int_unsigned , q_bigint_unsigned , q_smallint_unsigned , q_tinyint_unsigned , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values('{self.ts + 100000000}', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}')
                            ('{self.ts + column_i*500000000 + 5 }', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + 1000000000000 + 1 }', '{column_i - 25}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            {database}.regular_table_5  (ts , ts_pk ) values('{self.ts + 100000000 + 10 }', '{column_i - 25}')('{self.ts + column_i*500000000 + 15 }', '{column_i - 25}')('{self.ts + 1000000000000 + 11 }', '{column_i - 25}')   
                
                            {database}.regular_table_6  (ts , ts_pk , q_int , q_bigint , q_smallint , q_tinyint ,q_int_unsigned , q_bigint_unsigned , q_smallint_unsigned , q_tinyint_unsigned , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values('{self.ts + 100000000}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + column_i*600000000 + 6 }', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            ('{self.ts + 10000000000000 + 1 }', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i * updata_num}', '{column_i}', '{column_i * updata_num}', '{column_i * updata_num}', 0, 'binary.{column_i * updata_num}', 'nchar.{column_i * updata_num}', '{column_i * updata_num}') 
                            {database}.regular_table_6  (ts , ts_pk ) values('{self.ts + 100000000 + 10 }', '{column_i}')('{self.ts + column_i*600000000 + 16 }', '{column_i}') ('{self.ts + 10000000000000 + 11 }', '{column_i}');''' ) 
           
        else:
            tdSql.execute('''use %s;'''%database)

        if deletedata != 'yes':     
            i = random.randint(0,4)
            if i ==0:
                tdLog.info("======this case test use flush database =========")
                tdSql.execute("flush database %s;" %database) 
            elif i ==1:  
                tdLog.info("======this case test use flush database =========")
                tdSql.execute("flush database %s;" %database)   
                tdLog.info("======this case test keepcolumnname = 1 =========")  
                tdSql.execute("alter local 'keepcolumnname' '1';")  
            elif i ==2:  
                tdLog.info("======this case test use flush database =========")
                tdSql.execute("flush database %s;" %database)   
                tdLog.info("======this case test keepcolumnname = 0 =========")  
                tdSql.execute("alter local 'keepcolumnname' '0';")  
            else:
                tdLog.info("===!!!===this case test not use flush database =====!!!====")
            
            tdSql.query("select count(*) from %s.stable_1;"%database)
            tdSql.checkData(0,0,10*60*once_insert_num)
            tdSql.query("select count(*) from %s.regular_table_1;"%database)
            tdSql.checkData(0,0,60*once_insert_num)
            
            tdSql.query("select count(*) from %s.stable_0;"%database)
            tdSql.checkData(0,0,10*24*once_insert_num)
            tdSql.query("select count(*) from %s.regular_table_0;"%database)
            tdSql.checkData(0,0,24*once_insert_num)
            
            stable_list = ['stable_1','stable_2','stable_3','stable_4','stable_5','stable_6']
            for i in stable_list:
                tdSql.query("select count(*) from {}.{};".format(database, i))
                tdSql.checkData(0,0,10*60*once_insert_num)
            table_list = ['regular_table_1','regular_table_2','regular_table_3','regular_table_4','regular_table_5','regular_table_6']
            for i in table_list:
                tdSql.query("select count(*) from {}.{};".format(database, i))
                tdSql.checkData(0,0,60*once_insert_num)
            
            self.alter_cachemodel(database)
            
            tdSql.query("select count(*) from %s.stable_1;"%database)
            tdSql.checkData(0,0,10*60*once_insert_num)
            tdSql.query("select count(*) from %s.regular_table_1;"%database)
            tdSql.checkData(0,0,60*once_insert_num)
            tdSql.query("select count(*) from %s.stable_0 group by tbname;"%database)
            tdSql.checkData(0,0,24*once_insert_num)
            tdSql.checkData(2,0,24*once_insert_num)
            tdSql.checkData(4,0,24*once_insert_num)
            
            stable_list = ['stable_1','stable_2','stable_3','stable_4','stable_5','stable_6']
            for i in stable_list:
                tdSql.query("select count(*) from {}.{} group by tbname;".format(database, i))
                tdSql.checkData(0,0,60*once_insert_num)
                tdSql.checkData(2,0,60*once_insert_num)
                tdSql.checkData(4,0,60*once_insert_num)
                tdSql.checkData(6,0,60*once_insert_num)
                tdSql.checkData(8,0,60*once_insert_num)
            table_list = ['regular_table_1','regular_table_2','regular_table_3','regular_table_4','regular_table_5','regular_table_6']
            for i in table_list:
                tdSql.query("select count(*) from {}.{};".format(database, i))
                tdSql.checkData(0,0,60*once_insert_num)

        #delete data
        if deletedata == 'yes':            
            for tag_i in range(1,11):
                for column_i in range(49,51):    
                    tdSql.execute(f'''delete from {database}.stable_0_{tag_i}  where ts = {self.ts + 100000000};''' ) 
                    tdSql.execute(f'''delete from {database}.stable_0_{tag_i}  where ts = {self.ts + column_i*100000000 + 1 };''' )
                    tdSql.execute(f'''delete from {database}.stable_0_{tag_i}  where ts = {self.ts + 2000000000 - 1000000000 + 2 };''' ) 
                    tdSql.execute(f'''delete from {database}.stable_0_{tag_i}  where ts = {self.ts + 100000000 + 10 };''' ) 
                    tdSql.execute(f'''delete from {database}.stable_0_{tag_i}  where ts = {self.ts + column_i*100000000 + 11 };''' )
                    tdSql.execute(f'''delete from {database}.stable_0_{tag_i}  where ts = {self.ts + 2000000000 - 1000000000 + 12 };''' ) 
                    
                    tdSql.execute(f'''delete from {database}.stable_1_{tag_i}  where ts = {self.ts + 100000000} ;''' ) 
                    tdSql.execute(f'''delete from {database}.stable_1_{tag_i}  where ts = {self.ts + column_i*100000000 + 1 };''' )
                    tdSql.execute(f'''delete from {database}.stable_1_{tag_i}  where ts = {self.ts + 2000000000 - 1000000000 + 2 };''' ) 
                    tdSql.execute(f'''delete from {database}.stable_1_{tag_i}  where ts = {self.ts + 100000000 + 10 }  ;''' ) 
                    tdSql.execute(f'''delete from {database}.stable_1_{tag_i}  where ts = {self.ts + column_i*100000000 + 11 } ;''' )
                    tdSql.execute(f'''delete from {database}.stable_1_{tag_i}  where ts = {self.ts + 2000000000 - 1000000000 + 12 } ;''' ) 
                    
                    tdSql.execute(f'''delete from {database}.stable_2_{tag_i}  where ts = {self.ts + 100000000};''' ) 
                    tdSql.execute(f'''delete from {database}.stable_2_{tag_i}  where ts = {self.ts + column_i*200000000 + 2 };''' )
                    tdSql.execute(f'''delete from {database}.stable_2_{tag_i}  where ts = {self.ts + 1000000000 + 1 };''' ) 
                    tdSql.execute(f'''delete from {database}.stable_2_{tag_i}  where ts = {self.ts + 100000000 + 10 };''' ) 
                    tdSql.execute(f'''delete from {database}.stable_2_{tag_i}  where ts = {self.ts + column_i*200000000 + 12 };''' )
                    tdSql.execute(f'''delete from {database}.stable_2_{tag_i}  where ts = {self.ts + 1000000000 + 11 };''' ) 
                    
                    tdSql.execute(f'''delete from {database}.stable_3_{tag_i}  where ts = {self.ts + 100000000};''' ) 
                    tdSql.execute(f'''delete from {database}.stable_3_{tag_i}  where ts = {self.ts + column_i*300000000 + 3 };''' )
                    tdSql.execute(f'''delete from {database}.stable_3_{tag_i}  where ts = {self.ts + 10000000000 + 1 };''' ) 
                    tdSql.execute(f'''delete from {database}.stable_3_{tag_i}  where ts = {self.ts + 100000000 + 10 };''' ) 
                    tdSql.execute(f'''delete from {database}.stable_3_{tag_i}  where ts = {self.ts + column_i*300000000 + 13 };''' )
                    tdSql.execute(f'''delete from {database}.stable_3_{tag_i}  where ts = {self.ts + 10000000000 + 11 };''' ) 
                    
                    tdSql.execute(f'''delete from {database}.stable_4_{tag_i}  where ts = {self.ts + 100000000};''' ) 
                    tdSql.execute(f'''delete from {database}.stable_4_{tag_i}  where ts = {self.ts + column_i*400000000 + 4 };''' )
                    tdSql.execute(f'''delete from {database}.stable_4_{tag_i}  where ts = {self.ts + 100000000000 + 1 };''' ) 
                    tdSql.execute(f'''delete from {database}.stable_4_{tag_i}  where ts = {self.ts + 100000000 + 10 };''' ) 
                    tdSql.execute(f'''delete from {database}.stable_4_{tag_i}  where ts = {self.ts + column_i*400000000 + 14 };''' )
                    tdSql.execute(f'''delete from {database}.stable_4_{tag_i}  where ts = {self.ts + 100000000000 + 11 };''' ) 
                    
                    tdSql.execute(f'''delete from {database}.stable_5_{tag_i}  where ts = {self.ts + 100000000};''' ) 
                    tdSql.execute(f'''delete from {database}.stable_5_{tag_i}  where ts = {self.ts + column_i*500000000 + 5 };''' )
                    tdSql.execute(f'''delete from {database}.stable_5_{tag_i}  where ts = {self.ts + 1000000000000 + 1 };''' ) 
                    tdSql.execute(f'''delete from {database}.stable_5_{tag_i}  where ts = {self.ts + 100000000 + 10 };''' ) 
                    tdSql.execute(f'''delete from {database}.stable_5_{tag_i}  where ts = {self.ts + column_i*500000000 + 15 };''' )
                    tdSql.execute(f'''delete from {database}.stable_5_{tag_i}  where ts = {self.ts + 1000000000000 + 11 };''' ) 
                    
                    tdSql.execute(f'''delete from {database}.stable_6_{tag_i}  where ts = {self.ts + 100000000};''' ) 
                    tdSql.execute(f'''delete from {database}.stable_6_{tag_i}  where ts = {self.ts + column_i*600000000 + 6 };''' )
                    tdSql.execute(f'''delete from {database}.stable_6_{tag_i}  where ts = {self.ts + 10000000000000 + 1 };''' ) 
                    tdSql.execute(f'''delete from {database}.stable_6_{tag_i}  where ts = {self.ts + 100000000 + 10 };''' ) 
                    tdSql.execute(f'''delete from {database}.stable_6_{tag_i}  where ts = {self.ts + column_i*600000000 + 16 };''' )
                    tdSql.execute(f'''delete from {database}.stable_6_{tag_i}  where ts = {self.ts + 10000000000000 + 11 };''' ) 
                
            for column_i in range(49,51):    
                tdSql.execute(f'''delete from {database}.regular_table_0  where ts = {self.ts + 100000000};''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_0  where ts = {self.ts + column_i*100000000 + 1 };''' )
                tdSql.execute(f'''delete from {database}.regular_table_0  where ts = {self.ts + 2000000000 - 1000000000 + 2 };''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_0  where ts = {self.ts + 100000000 + 10 };''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_0  where ts = {self.ts + column_i*100000000 + 11 };''' )
                tdSql.execute(f'''delete from {database}.regular_table_0  where ts = {self.ts + 2000000000 - 1000000000 + 12 };''' ) 
                    
                tdSql.execute(f'''delete from {database}.regular_table_1  where ts = {self.ts + 100000000};''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_1  where ts = {self.ts + column_i*100000000 + 1 };''' )
                tdSql.execute(f'''delete from {database}.regular_table_1  where ts = {self.ts + 2000000000 - 1000000000 + 2 };''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_1  where ts = {self.ts + 100000000 + 10 };''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_1  where ts = {self.ts + column_i*100000000 + 11 };''' )
                tdSql.execute(f'''delete from {database}.regular_table_1  where ts = {self.ts + 2000000000 - 1000000000 + 12 };''' ) 
                
                tdSql.execute(f'''delete from {database}.regular_table_2  where ts = {self.ts + 100000000};''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_2  where ts = {self.ts + column_i*200000000 + 2 };''' )
                tdSql.execute(f'''delete from {database}.regular_table_2  where ts = {self.ts + 1000000000 + 1 };''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_2  where ts = {self.ts + 100000000 + 10 };''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_2  where ts = {self.ts + column_i*200000000 + 12 };''' )
                tdSql.execute(f'''delete from {database}.regular_table_2  where ts = {self.ts + 1000000000 + 11 };''' ) 
                
                tdSql.execute(f'''delete from {database}.regular_table_3  where ts = {self.ts + 100000000};''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_3  where ts = {self.ts + column_i*300000000 + 3 };''' )
                tdSql.execute(f'''delete from {database}.regular_table_3  where ts = {self.ts + 10000000000 + 1 };''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_3  where ts = {self.ts + 100000000 + 10 };''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_3  where ts = {self.ts + column_i*300000000 + 13 };''' )
                tdSql.execute(f'''delete from {database}.regular_table_3  where ts = {self.ts + 10000000000 + 11 };''' ) 
                
                tdSql.execute(f'''delete from {database}.regular_table_4  where ts = {self.ts + 100000000};''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_4  where ts = {self.ts + column_i*400000000 + 4 };''' )
                tdSql.execute(f'''delete from {database}.regular_table_4  where ts = {self.ts + 100000000000 + 1 };''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_4  where ts = {self.ts + 100000000 + 10 };''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_4  where ts = {self.ts + column_i*400000000 + 14 };''' )
                tdSql.execute(f'''delete from {database}.regular_table_4  where ts = {self.ts + 100000000000 + 11 };''' ) 
                
                tdSql.execute(f'''delete from {database}.regular_table_5  where ts = {self.ts + 100000000};''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_5  where ts = {self.ts + column_i*500000000 + 5 };''' )
                tdSql.execute(f'''delete from {database}.regular_table_5  where ts = {self.ts + 1000000000000 + 1 };''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_5  where ts = {self.ts + 100000000 + 10 };''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_5  where ts = {self.ts + column_i*500000000 + 15 };''' )
                tdSql.execute(f'''delete from {database}.regular_table_5  where ts = {self.ts + 1000000000000 + 11 };''' ) 
                
                tdSql.execute(f'''delete from {database}.regular_table_6  where ts = {self.ts + 100000000};''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_6  where ts = {self.ts + column_i*600000000 + 6 };''' )
                tdSql.execute(f'''delete from {database}.regular_table_6  where ts = {self.ts + 10000000000000 + 1 };''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_6  where ts = {self.ts + 100000000 + 10 };''' ) 
                tdSql.execute(f'''delete from {database}.regular_table_6  where ts = {self.ts + column_i*600000000 + 16 };''' )
                tdSql.execute(f'''delete from {database}.regular_table_6  where ts = {self.ts + 10000000000000 + 11 };''' ) 
                            
        else:
            tdSql.execute('''use %s;'''%database)
                    
        #delete data
        if deletedata == 'yes':    
            i = random.randint(0,4)
            if i ==0:
                tdLog.info("======this case test use flush database =========")
                tdSql.execute("flush database %s;" %database) 
            elif i ==1:  
                tdLog.info("======this case test use flush database =========")
                tdSql.execute("flush database %s;" %database)   
                tdLog.info("======this case test keepcolumnname = 1 =========")  
                tdSql.execute("alter local 'keepcolumnname' '1';")  
            elif i ==2:  
                tdLog.info("======this case test use flush database =========")
                tdSql.execute("flush database %s;" %database)   
                tdLog.info("======this case test keepcolumnname = 0 =========")  
                tdSql.execute("alter local 'keepcolumnname' '0';")  
            else:
                tdLog.info("===!!!===this case test not use flush database =====!!!====")
            
            tdSql.query("select count(*) from %s.stable_1;"%database)
            tdSql.checkData(0,0,10*96*once_insert_num)
            tdSql.query("select count(*) from %s.regular_table_1;"%database)
            tdSql.checkData(0,0,96*once_insert_num)
            
            tdSql.query("select count(*) from %s.stable_0;"%database)
            tdSql.checkData(0,0,10*96*once_insert_num)
            tdSql.query("select count(*) from %s.regular_table_0;"%database)
            tdSql.checkData(0,0,96*once_insert_num)
            
            stable_list = ['stable_1','stable_2','stable_3','stable_4','stable_5','stable_6']
            for i in stable_list:
                tdSql.query("select count(*) from {}.{};".format(database, i))
                tdSql.checkData(0,0,10*96*once_insert_num)
            table_list = ['regular_table_1','regular_table_2','regular_table_3','regular_table_4','regular_table_5','regular_table_6']
            for i in table_list:
                tdSql.query("select count(*) from {}.{};".format(database, i))
                tdSql.checkData(0,0,96*once_insert_num)
            
            self.alter_cachemodel(database)
            
            tdSql.query("select count(*) from %s.stable_1;"%database)
            tdSql.checkData(0,0,10*96*once_insert_num)
            tdSql.query("select count(*) from %s.regular_table_1;"%database)
            tdSql.checkData(0,0,96*once_insert_num)
            tdSql.query("select count(*) from %s.stable_0 group by tbname;"%database)
            tdSql.checkData(0,0,96*once_insert_num)
            tdSql.checkData(2,0,96*once_insert_num)
            tdSql.checkData(4,0,96*once_insert_num)
            
            stable_list = ['stable_1','stable_2','stable_3','stable_4','stable_5','stable_6']
            for i in stable_list:
                tdSql.query("select count(*) from {}.{} group by tbname;".format(database, i))
                tdSql.checkData(0,0,96*once_insert_num)
                tdSql.checkData(2,0,96*once_insert_num)
                tdSql.checkData(4,0,96*once_insert_num)
                tdSql.checkData(6,0,96*once_insert_num)
                tdSql.checkData(8,0,96*once_insert_num)
            table_list = ['regular_table_1','regular_table_2','regular_table_3','regular_table_4','regular_table_5','regular_table_6']
            for i in table_list:
                tdSql.query("select count(*) from {}.{};".format(database, i))
                tdSql.checkData(0,0,96*once_insert_num)
                    
    def value_check(self,base_value,check_value):
        if base_value==check_value:
            tdLog.info(f"checkEqual success, base_value={base_value},check_value={check_value}") 
        else :
            tdLog.exit(f"checkEqual error, base_value={base_value},check_value={check_value}") 

    def explain_sql_pass(self,sql):
        sql = "explain verbose true " + sql 
        tdSql.query(sql)
                
    def alter_cachemodel(self,database):
        tdSql.query("alter local 'schedulePolicy' '%d';" %random.randint(1,3))
        i = random.randint(0,5)
        cachesize = random.randint(1,100)
        if i ==0:
            tdLog.info("======this case test cachemodel none =========") 
        elif i ==1:
            tdLog.info("======this case test cachemodel last_row =========")
            sql = "alter database %s cachemodel 'last_row' cachesize %d;"  %(database,cachesize)
            tdSql.query(sql,queryTimes=1)  
        elif i ==2:
            tdLog.info("======this case test cachemodel last_value =========")
            sql = "alter database %s cachemodel 'last_value' cachesize %d;"  %(database,cachesize)
            tdSql.query(sql,queryTimes=1)
        else:
            tdLog.info("======this case test cachemodel both =========")
            sql = "alter database %s cachemodel 'both' cachesize %d;"  %(database,cachesize)
            tdSql.query(sql,queryTimes=1)

    def query_pk(self,database,num=1):

        self.fun_pk_interp(self.database,'interp','') 
        self.multiple_agg_groupby(self.database,1) 
        self.fun_pk_diff(self.database,'diff','') 
        self.fun_pk_twa(self.database,'derivative',',1s,0') 
        self.fun_pk_twa(self.database,'derivative',',1s,1') 
        self.fun_pk_unique(self.database,'unique','')  
        self.fun_pk_last_init(self.database,'last','')  
        self.fun_pk_last(self.database,'last','')  
        self.fun_pk_last(self.database,'last_row','') 
        self.fun_pk_first(self.database,'first','') 
        
        self.query_pk_fun(self.database,'') 
        
        self.touying_pk_1(self.database,1) 
        self.touying_pk_where(self.database,'') 
        self.touying_pk_where(self.database,'tags') 
        self.touying_pk_where(self.database,'distinct') 
        self.count_pk(self.database,1) 

    def count_pk(self,db,num=1):
        stable_list = ['stable_1','stable_2','stable_3','stable_4','stable_5','stable_6']
        for i in stable_list:
            tdSql.query("select count(*) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(ts) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(ts_pk) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(q_int) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*30*num)
            tdSql.query("select count(q_bigint) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*30*num)
            tdSql.query("select count(q_smallint) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*30*num)
            tdSql.query("select count(q_tinyint) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*30*num)
            tdSql.query("select count(q_int_unsigned) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*30*num)
            tdSql.query("select count(q_bigint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*30*num)
            tdSql.query("select count(q_smallint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*30*num)
            tdSql.query("select count(q_tinyint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*30*num)
            tdSql.query("select count(q_float) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*30*num)
            tdSql.query("select count(q_double) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*30*num)
            tdSql.query("select count(q_bool) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*30*num)
            tdSql.query("select count(q_binary) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*30*num)
            tdSql.query("select count(q_nchar) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*30*num)
            tdSql.query("select count(q_ts) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*30*num)
            tdSql.query("select count(q_int_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*0*num)
            tdSql.query("select count(q_bigint_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*0*num)
            tdSql.query("select count(q_smallint_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*0*num)
            tdSql.query("select count(q_tinyint_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*0*num)
            tdSql.query("select count(q_float_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*0*num)
            tdSql.query("select count(q_double_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*0*num)
            tdSql.query("select count(q_bool_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*0*num)
            tdSql.query("select count(q_binary_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*0*num)
            tdSql.query("select count(q_nchar_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*0*num)
            tdSql.query("select count(q_ts_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*0*num)
            tdSql.query("select count(tbname) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(loc) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(t_int) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(t_bigint) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(t_smallint) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(t_tinyint) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(t_int_unsigned) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(t_bigint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(t_smallint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(t_tinyint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(t_float) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(t_double) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(t_bool) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(t_binary) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(t_nchar) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            tdSql.query("select count(t_ts) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,10*60*num)
            
            #window
            sql = "select _wstart,count(ts) from {}.stable_0 interval(1s)".format(db)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.stable_0 interval(1a)".format(db)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} interval(1s)".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.{} interval(1a)".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} state_window(ts_pk)".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} session(ts,1s)".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.{} session(ts,1a)".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} event_window start with ts_pk >0 end with ts_pk <=10 ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.{} event_window start with ts_pk >0 end with ts_pk <=10 ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} count_window(10)".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.{} count_window(10)".format(db, i)
            self.explain_sql_pass(sql)

        table_list = ['regular_table_1','regular_table_2','regular_table_3','regular_table_4','regular_table_5','regular_table_6']
        for i in table_list:
            tdSql.query("select count(*) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(ts) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(ts_pk) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(q_int) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bigint) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_smallint) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_tinyint) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_int_unsigned) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bigint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_smallint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_tinyint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_float) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_double) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bool) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_binary) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_nchar) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_ts) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_int_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_bigint_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_smallint_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_tinyint_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_float_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_double_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_bool_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_binary_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_nchar_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_ts_null) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(tbname) from {}.{} ".format(db, i))
            tdSql.checkData(0,0,60*num)
    
            #window
            sql = "select _wstart,count(ts) from {}.regular_table_0 interval(1s)".format(db)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.regular_table_0 interval(1a)".format(db)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} interval(1s)".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.{} interval(1a)".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} state_window(ts_pk)".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} session(ts,1s)".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.{} session(ts,1a)".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} event_window start with ts_pk >0 end with ts_pk <=10 ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.{} event_window start with ts_pk >0 end with ts_pk <=10 ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} count_window(10)".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.{} count_window(10)".format(db, i)
            self.explain_sql_pass(sql)

        stable_list = ['stable_1','stable_2','stable_3','stable_4','stable_5','stable_6']
        for i in stable_list:
            tdSql.query("select count(*) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.checkData(2,0,60*num)
            tdSql.checkData(4,0,60*num)
            tdSql.checkData(6,0,60*num)
            tdSql.checkData(8,0,60*num)   
            
            tdSql.query("select count(ts) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(ts_pk) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(1,0,60*num)
            tdSql.query("select count(q_int) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(2,0,30*num)
            tdSql.query("select count(q_bigint) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(3,0,30*num)
            tdSql.query("select count(q_smallint) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(4,0,30*num)
            tdSql.query("select count(q_tinyint) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(5,0,30*num)
            tdSql.query("select count(q_int_unsigned) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(6,0,30*num)
            tdSql.query("select count(q_bigint_unsigned) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(7,0,30*num)
            tdSql.query("select count(q_smallint_unsigned) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(8,0,30*num)
            tdSql.query("select count(q_tinyint_unsigned) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(9,0,30*num)
            tdSql.query("select count(q_float) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_double) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(1,0,30*num)
            tdSql.query("select count(q_bool) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(2,0,30*num)
            tdSql.query("select count(q_binary) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(3,0,30*num)
            tdSql.query("select count(q_nchar) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(4,0,30*num)
            tdSql.query("select count(q_ts) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(5,0,30*num)
            tdSql.query("select count(q_int_null) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(6,0,0*num)
            tdSql.query("select count(q_bigint_null) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(7,0,0*num)
            tdSql.query("select count(q_smallint_null) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(8,0,0*num)
            tdSql.query("select count(q_tinyint_null) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(9,0,0*num)
            tdSql.query("select count(q_float_null) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_double_null) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(1,0,0*num)
            tdSql.query("select count(q_bool_null) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(2,0,0*num)
            tdSql.query("select count(q_binary_null) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(3,0,0*num)
            tdSql.query("select count(q_nchar_null) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(4,0,0*num)
            tdSql.query("select count(q_ts_null) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(5,0,0*num)
            tdSql.query("select count(tbname) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(6,0,60*num)
            tdSql.query("select count(loc) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(7,0,60*num)
            tdSql.query("select count(t_int) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(8,0,60*num)
            tdSql.query("select count(t_bigint) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(9,0,60*num)
            tdSql.query("select count(t_smallint) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(t_tinyint) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(1,0,60*num)
            tdSql.query("select count(t_int_unsigned) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(2,0,60*num)
            tdSql.query("select count(t_bigint_unsigned) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(3,0,60*num)
            tdSql.query("select count(t_smallint_unsigned) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(4,0,60*num)
            tdSql.query("select count(t_tinyint_unsigned) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(5,0,60*num)
            tdSql.query("select count(t_float) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(6,0,60*num)
            tdSql.query("select count(t_double) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(7,0,60*num)
            tdSql.query("select count(t_bool) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(8,0,60*num)
            tdSql.query("select count(t_binary) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(9,0,60*num)
            tdSql.query("select count(t_nchar) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(t_ts) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(1,0,60*num)
            
            #window
            sql = "select _wstart,count(ts) from {}.stable_0 partition by tbname interval(1s) order by _wstart ".format(db)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.stable_0 partition by tbname interval(1a) order by _wstart ".format(db)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} partition by tbname interval(1s) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.{} partition by tbname interval(1a) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} partition by tbname state_window(ts_pk) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} partition by tbname session(ts,1s) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.{} partition by tbname session(ts,1a) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} partition by tbname event_window start with ts_pk >0 end with ts_pk <=10  order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.{} partition by tbname event_window start with ts_pk >0 end with ts_pk <=10  order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} partition by tbname count_window(10) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.{} partition by tbname count_window(10) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)

        table_list = ['regular_table_1','regular_table_2','regular_table_3','regular_table_4','regular_table_5','regular_table_6']
        for i in table_list:
            tdSql.query("select count(*) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)  
            
            tdSql.query("select count(ts) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(ts_pk) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(q_int) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bigint) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_smallint) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_tinyint) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_int_unsigned) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bigint_unsigned) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_smallint_unsigned) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_tinyint_unsigned) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_float) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_double) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bool) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_binary) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_nchar) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_ts) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_int_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_bigint_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_smallint_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_tinyint_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_float_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_double_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_bool_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_binary_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_nchar_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_ts_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(tbname) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
    
        #window
            sql = "select _wstart,count(ts) from {}.regular_table_0 partition by tbname interval(1s)".format(db)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.regular_table_0 partition by tbname interval(1a)".format(db)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} partition by tbname interval(1s)".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.{} partition by tbname interval(1a)".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} partition by tbname state_window(ts_pk)".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} partition by tbname session(ts,1s)".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.{} partition by tbname session(ts,1a)".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} partition by tbname event_window start with ts_pk >0 end with ts_pk <=10 ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.{} partition by tbname event_window start with ts_pk >0 end with ts_pk <=10 ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts) from {}.{} partition by tbname count_window(10)".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts) from {}.{} partition by tbname count_window(10)".format(db, i)
            self.explain_sql_pass(sql)

    def touying_pk_1(self,db,num=1):
        stable_list = ['stable_1','stable_2','stable_3','stable_4','stable_5','stable_6']
        for i in stable_list:
            tdSql.query("select * from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (ts) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (ts_pk) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_int) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_bigint) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_smallint) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_tinyint) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_int_unsigned) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_bigint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_smallint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_tinyint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_float) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_double) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_bool) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_binary) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_nchar) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_ts) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_int_null) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_bigint_null) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_smallint_null) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_tinyint_null) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_float_null) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_double_null) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_bool_null) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_binary_null) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_nchar_null) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_ts_null) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (tbname) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (loc) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_int) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_bigint) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_smallint) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_tinyint) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_int_unsigned) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_bigint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_smallint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_tinyint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_float) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_double) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_bool) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_binary) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_nchar) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_ts) from {}.{} ".format(db, i))
            tdSql.checkRows(10*60*num)

        table_list = ['regular_table_1','regular_table_2','regular_table_3','regular_table_4','regular_table_5','regular_table_6']
        for i in table_list:
            tdSql.query("select * from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (ts) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (ts_pk) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_int) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_bigint) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_smallint) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_tinyint) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_int_unsigned) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_bigint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_smallint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_tinyint_unsigned) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_float) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_double) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_bool) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_binary) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_nchar) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_ts) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_int_null) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_bigint_null) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_smallint_null) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_tinyint_null) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_float_null) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_double_null) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_bool_null) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_binary_null) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_nchar_null) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (q_ts_null) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)
            tdSql.query("select (tbname) from {}.{} ".format(db, i))
            tdSql.checkRows(60*num)

        stable_list = ['stable_1','stable_2','stable_3','stable_4','stable_5','stable_6']
        for i in stable_list:
            tdSql.query("select * from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num) 
            
            tdSql.query("select (ts) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num) 
            tdSql.query("select (ts_pk) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_int) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_bigint) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_smallint) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_tinyint) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_int_unsigned) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_bigint_unsigned) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_smallint_unsigned) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_tinyint_unsigned) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_float) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_double) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_bool) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_binary) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_nchar) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_ts) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_int_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_bigint_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_smallint_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_tinyint_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_float_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_double_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_bool_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_binary_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_nchar_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (q_ts_null) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (tbname) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (loc) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_int) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_bigint) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_smallint) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_tinyint) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_int_unsigned) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_bigint_unsigned) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_smallint_unsigned) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_tinyint_unsigned) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_float) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_double) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_bool) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_binary) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_nchar) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)
            tdSql.query("select (t_ts) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkRows(10*60*num)

    def touying_pk_where(self,db,replace_fun,num=1):
        stable_list = ['stable_1','stable_2','stable_3','stable_4','stable_5','stable_6']
        for i in stable_list:
            sql = "select {} * from {}.{} where ts is not null order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(10*60*num)
            sql = "select {} * from {}.{} where ts is not null order by ts desc ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(10*60*num)
            sql = "select {} * from {}.{} where ts is not null order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(10*60*num)
            sql = "select {} * from {}.{} where ts is not null order by ts desc ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(10*60*num)
            sql = "select {} * from {}.{} where ts_pk is not null order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(10*60*num)
            sql = "select {} * from {}.{} where ts_pk is not null order by ts desc ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(10*60*num)
            sql = "select {} * from {}.{} where ts_pk = '1' order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(10*0*num)
            sql = "select {} * from {}.{} where ts_pk != '1' order by ts desc ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(10*60*num)
            sql = "select {} * from {}.{} where ts_pk in ('1','11','111') order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(10*0*num)
            sql = "select {} * from {}.{} where ts_pk not in ('1','11','111') order by ts desc".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(10*60*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) between 1 and 10 order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(10*0*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) not between 1 and 10 order by ts desc".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(10*60*num)   
                 
            sql = "select cc from (select {} count(*) cc from {}.{} group by ts_pk ) where cc != 60 ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(0)           
            sql = "select cc from (select {} count(*) cc from {}.{} group by ts_pk order by cc ) where cc != 60 ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(0)           
            sql = "select cc from (select {} count(*) cc from {}.{} group by ts_pk order by cc desc ) where cc != 60 ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(0)
        
        stable_list = ['stable_1','stable_3','stable_5']
        for i in stable_list:   
            sql = "select {} * from {}.{} where cast(ts_pk as int) < 10 order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(10*0*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) >= 10 order by ts desc ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(10*60*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) <= 20 order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(10*30*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) > 20 order by ts desc ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(10*30*num)   
            
        stable_list = ['stable_2','stable_4','stable_6']
        for i in stable_list:   
            sql = "select {} * from {}.{} where cast(ts_pk as int) < 10 order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(10*0*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) >= 10 order by ts desc ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(10*60*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) <= 20 order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(10*0*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) > 20 order by ts desc ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(10*60*num)   
            
        table_list = ['regular_table_1','regular_table_3','regular_table_5']
        for i in table_list:   
            sql = "select {} * from {}.{} where cast(ts_pk as int) < 10 order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(0*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) >= 10 order by ts desc ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(60*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) <= 20 order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(30*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) > 20 order by ts desc ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(30*num)   
            
        table_list = ['regular_table_2','regular_table_4','regular_table_6']
        for i in table_list:   
            sql = "select {} * from {}.{} where cast(ts_pk as int) < 10 order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(0*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) >= 10 order by ts desc ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(60*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) <= 20 order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(0*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) > 20 order by ts desc ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(60*num)   
        
        table_list = ['regular_table_1','regular_table_2','regular_table_3','regular_table_4','regular_table_5','regular_table_6']
        for i in table_list:
            sql = "select {} * from {}.{} where ts is not null order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(60*num)
            sql = "select {} * from {}.{} where ts is not null order by ts desc ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(60*num)
            sql = "select {} * from {}.{} where ts is not null order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(60*num)
            sql = "select {} * from {}.{} where ts is not null order by ts desc ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(60*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) is not null order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(60*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) is not null order by ts desc ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(60*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) = 1 order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(0*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) != 1 order by ts desc ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(60*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) in (1,11,111) order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(0*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) not in (1,11,111) order by ts desc ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(60*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) between 1 and 10 order by ts ".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(0*num)
            sql = "select {} * from {}.{} where cast(ts_pk as int) not between 1 and 10 order by ts desc".format(replace_fun,db, i)
            tdSql.query(sql)
            tdSql.checkRows(60*num)
                   
            sql = "select cc from (select {} count(*) cc from {}.{} group by ts_pk ) where cc != 6 ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(0)           
            sql = "select cc from (select {} count(*) cc from {}.{} group by ts_pk order by cc ) where cc != 6 ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(0)           
            sql = "select cc from (select {} count(*) cc from {}.{} group by ts_pk order by cc desc ) where cc != 6 ".format(replace_fun, db,i)
            tdSql.query(sql)
            tdSql.checkRows(0)

    def multiple_agg_groupby(self,db,num=1):
        #TD-29093
        stable_list = ['stable_1','stable_2','stable_3','stable_4','stable_5','stable_6']
        for i in stable_list:
            tdSql.query("select count(*),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.checkData(2,0,60*num)
            tdSql.checkData(4,0,60*num)
            tdSql.checkData(6,0,60*num)
            tdSql.checkData(8,0,60*num)   
            
            tdSql.query("select count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(ts_pk),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(1,0,60*num)
            tdSql.query("select count(q_int),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(2,0,30*num)
            tdSql.query("select count(q_bigint),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(3,0,30*num)
            tdSql.query("select count(q_smallint),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(4,0,30*num)
            tdSql.query("select count(q_tinyint),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(5,0,30*num)
            tdSql.query("select count(q_int_unsigned),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(6,0,30*num)
            tdSql.query("select count(q_bigint_unsigned),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(7,0,30*num)
            tdSql.query("select count(q_smallint_unsigned),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(8,0,30*num)
            tdSql.query("select count(q_tinyint_unsigned),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(9,0,30*num)
            tdSql.query("select count(q_float),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_double),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(1,0,30*num)
            tdSql.query("select count(q_bool),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(2,0,30*num)
            tdSql.query("select count(q_binary),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(3,0,30*num)
            tdSql.query("select count(q_nchar),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(4,0,30*num)
            tdSql.query("select count(q_ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(5,0,30*num)
            tdSql.query("select count(q_int_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(6,0,0*num)
            tdSql.query("select count(q_bigint_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(7,0,0*num)
            tdSql.query("select count(q_smallint_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(8,0,0*num)
            tdSql.query("select count(q_tinyint_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(9,0,0*num)
            tdSql.query("select count(q_float_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_double_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(1,0,0*num)
            tdSql.query("select count(q_bool_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(2,0,0*num)
            tdSql.query("select count(q_binary_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(3,0,0*num)
            tdSql.query("select count(q_nchar_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(4,0,0*num)
            tdSql.query("select count(q_ts_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(5,0,0*num)
            tdSql.query("select count(tbname),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(6,0,60*num)
            tdSql.query("select count(loc),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(7,0,60*num)
            tdSql.query("select count(t_int),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(8,0,60*num)
            tdSql.query("select count(t_bigint),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(9,0,60*num)
            tdSql.query("select count(t_smallint),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(t_tinyint),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(1,0,60*num)
            tdSql.query("select count(t_int_unsigned),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(2,0,60*num)
            tdSql.query("select count(t_bigint_unsigned),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(3,0,60*num)
            tdSql.query("select count(t_smallint_unsigned),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(4,0,60*num)
            tdSql.query("select count(t_tinyint_unsigned),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(5,0,60*num)
            tdSql.query("select count(t_float),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(6,0,60*num)
            tdSql.query("select count(t_double),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(7,0,60*num)
            tdSql.query("select count(t_bool),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(8,0,60*num)
            tdSql.query("select count(t_binary),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(9,0,60*num)
            tdSql.query("select count(t_nchar),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(t_ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by tbname ".format(db, i))
            tdSql.checkData(1,0,60*num)
            
            #window
            sql = "select _wstart,count(ts),tbname,first(ts),last(ts),last_row(ts),sum(cast(ts as int)),avg(cast(ts as int)),max(cast(ts as int)),min(cast(ts as int)) from {}.stable_0 partition by tbname interval(1s) order by _wstart ".format(db)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,first(ts),last(ts),last_row(ts),sum(cast(ts as int)),avg(cast(ts as int)),max(cast(ts as int)),min(cast(ts as int)) from {}.stable_0 partition by tbname interval(1a) order by _wstart ".format(db)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname interval(1s) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname interval(1a) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname state_window(ts_pk) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname session(ts,1s) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname session(ts,1a) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname event_window start with ts_pk >0 end with ts_pk <=10  order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname event_window start with ts_pk >0 end with ts_pk <=10  order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname count_window(10) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname count_window(10) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)

        table_list = ['regular_table_1','regular_table_2','regular_table_3','regular_table_4','regular_table_5','regular_table_6']
        for i in table_list:
            tdSql.query("select count(*),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)  
            
            tdSql.query("select count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(ts_pk),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(q_int),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bigint),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_smallint),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_tinyint),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_int_unsigned),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bigint_unsigned),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_smallint_unsigned),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_tinyint_unsigned),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_float),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_double),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bool),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_binary),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_nchar),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_int_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_bigint_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_smallint_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_tinyint_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_float_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_double_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_bool_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_binary_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_nchar_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_ts_null),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(tbname),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
    
        #window
            sql = "select _wstart,count(ts),tbname,first(ts),last(ts),last_row(ts),sum(cast(ts as int)),avg(cast(ts as int)),max(cast(ts as int)),min(cast(ts as int)) from {}.regular_table_0 partition by tbname interval(1s)".format(db)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,first(ts),last(ts),last_row(ts),sum(cast(ts as int)),avg(cast(ts as int)),max(cast(ts as int)),min(cast(ts as int)) from {}.regular_table_0 partition by tbname interval(1a)".format(db)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname interval(1s)".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname interval(1a)".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname state_window(ts_pk)".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname session(ts,1s)".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname session(ts,1a)".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname event_window start with ts_pk >0 end with ts_pk <=10 ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname event_window start with ts_pk >0 end with ts_pk <=10 ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname count_window(10)".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by tbname count_window(10)".format(db, i)
            self.explain_sql_pass(sql)
           
        #group by tag
        stable_list = ['stable_1','stable_2','stable_3','stable_4','stable_5','stable_6']
        for i in stable_list:
            tdSql.query("select count(*),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.checkData(2,0,60*num)
            tdSql.checkData(4,0,60*num)
            tdSql.checkData(6,0,60*num)
            tdSql.checkData(8,0,60*num)   
            
            tdSql.query("select count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(ts_pk),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(1,0,60*num)
            tdSql.query("select count(q_int),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(2,0,30*num)
            tdSql.query("select count(q_bigint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(3,0,30*num)
            tdSql.query("select count(q_smallint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(4,0,30*num)
            tdSql.query("select count(q_tinyint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(5,0,30*num)
            tdSql.query("select count(q_int_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(6,0,30*num)
            tdSql.query("select count(q_bigint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(7,0,30*num)
            tdSql.query("select count(q_smallint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(8,0,30*num)
            tdSql.query("select count(q_tinyint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(9,0,30*num)
            tdSql.query("select count(q_float),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_double),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(1,0,30*num)
            tdSql.query("select count(q_bool),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(2,0,30*num)
            tdSql.query("select count(q_binary),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(3,0,30*num)
            tdSql.query("select count(q_nchar),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(4,0,30*num)
            tdSql.query("select count(q_ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(5,0,30*num)
            tdSql.query("select count(q_int_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(6,0,0*num)
            tdSql.query("select count(q_bigint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(7,0,0*num)
            tdSql.query("select count(q_smallint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(8,0,0*num)
            tdSql.query("select count(q_tinyint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(9,0,0*num)
            tdSql.query("select count(q_float_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_double_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(1,0,0*num)
            tdSql.query("select count(q_bool_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(2,0,0*num)
            tdSql.query("select count(q_binary_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(3,0,0*num)
            tdSql.query("select count(q_nchar_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(4,0,0*num)
            tdSql.query("select count(q_ts_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(5,0,0*num)
            tdSql.query("select count(tbname),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(6,0,60*num)
            tdSql.query("select count(loc),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(7,0,60*num)
            tdSql.query("select count(t_int),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(8,0,60*num)
            tdSql.query("select count(t_bigint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(9,0,60*num)
            tdSql.query("select count(t_smallint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(t_tinyint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(1,0,60*num)
            tdSql.query("select count(t_int_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(2,0,60*num)
            tdSql.query("select count(t_bigint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(3,0,60*num)
            tdSql.query("select count(t_smallint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(4,0,60*num)
            tdSql.query("select count(t_tinyint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(5,0,60*num)
            tdSql.query("select count(t_float),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(6,0,60*num)
            tdSql.query("select count(t_double),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(7,0,60*num)
            tdSql.query("select count(t_bool),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(8,0,60*num)
            tdSql.query("select count(t_binary),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(9,0,60*num)
            tdSql.query("select count(t_nchar),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(t_ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname ".format(db, i))
            tdSql.checkData(1,0,60*num)
            
            #window
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts),last(ts),last_row(ts),sum(cast(ts as int)),avg(cast(ts as int)),max(cast(ts as int)),min(cast(ts as int)) from {}.stable_0 partition by loc,tbname interval(1s) order by _wstart ".format(db)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts),last(ts),last_row(ts),sum(cast(ts as int)),avg(cast(ts as int)),max(cast(ts as int)),min(cast(ts as int)) from {}.stable_0 partition by loc,tbname interval(1a) order by _wstart ".format(db)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname interval(1s) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname interval(1a) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname state_window(ts_pk) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname session(ts,1s) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname session(ts,1a) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname event_window start with ts_pk >0 end with ts_pk <=10  order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname event_window start with ts_pk >0 end with ts_pk <=10  order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname count_window(10) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname count_window(10) order by _wstart ".format(db, i)
            self.explain_sql_pass(sql)

        table_list = ['stable_1_1','stable_2_2','stable_3_3','stable_4_4','stable_5_5','stable_6_6']
        for i in table_list:
            tdSql.query("select count(*),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)  
            
            tdSql.query("select count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(ts_pk),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(q_int),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bigint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_smallint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_tinyint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_int_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bigint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_smallint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_tinyint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_float),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_double),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bool),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_binary),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_nchar),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_int_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_bigint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_smallint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_tinyint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_float_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_double_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_bool_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_binary_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_nchar_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_ts_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(tbname),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname ".format(db, i))
            tdSql.checkData(0,0,60*num)
    
        #window
            sql = "select _wstart,count(ts),tbname,first(ts),last(ts),last_row(ts),sum(cast(ts as int)),avg(cast(ts as int)),max(cast(ts as int)),min(cast(ts as int)) from {}.regular_table_0 partition by tbname,tbname interval(1s)".format(db)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,first(ts),last(ts),last_row(ts),sum(cast(ts as int)),avg(cast(ts as int)),max(cast(ts as int)),min(cast(ts as int)) from {}.regular_table_0 partition by tbname,tbname interval(1a)".format(db)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname interval(1s)".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname interval(1a)".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname state_window(ts_pk)".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname session(ts,1s)".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname session(ts,1a)".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname event_window start with ts_pk >0 end with ts_pk <=10 ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname event_window start with ts_pk >0 end with ts_pk <=10 ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname count_window(10)".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname count_window(10)".format(db, i)
            self.explain_sql_pass(sql)

        #group by tag + order by tag
        stable_list = ['stable_1','stable_2','stable_3','stable_4','stable_5','stable_6']
        for i in stable_list:
            tdSql.query("select count(*),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.checkData(2,0,60*num)
            tdSql.checkData(4,0,60*num)
            tdSql.checkData(6,0,60*num)
            tdSql.checkData(8,0,60*num)   
            
            tdSql.query("select count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(ts_pk),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(1,0,60*num)
            tdSql.query("select count(q_int),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(2,0,30*num)
            tdSql.query("select count(q_bigint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(3,0,30*num)
            tdSql.query("select count(q_smallint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts".format(db, i))
            tdSql.checkData(4,0,30*num)
            tdSql.query("select count(q_tinyint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(5,0,30*num)
            tdSql.query("select count(q_int_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(6,0,30*num)
            tdSql.query("select count(q_bigint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(7,0,30*num)
            tdSql.query("select count(q_smallint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(8,0,30*num)
            tdSql.query("select count(q_tinyint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(9,0,30*num)
            tdSql.query("select count(q_float),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_double),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(1,0,30*num)
            tdSql.query("select count(q_bool),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(2,0,30*num)
            tdSql.query("select count(q_binary),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(3,0,30*num)
            tdSql.query("select count(q_nchar),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(4,0,30*num)
            tdSql.query("select count(q_ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(5,0,30*num)
            tdSql.query("select count(q_int_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(6,0,0*num)
            tdSql.query("select count(q_bigint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(7,0,0*num)
            tdSql.query("select count(q_smallint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(8,0,0*num)
            tdSql.query("select count(q_tinyint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(9,0,0*num)
            tdSql.query("select count(q_float_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_double_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(1,0,0*num)
            tdSql.query("select count(q_bool_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(2,0,0*num)
            tdSql.query("select count(q_binary_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(3,0,0*num)
            tdSql.query("select count(q_nchar_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(4,0,0*num)
            tdSql.query("select count(q_ts_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(5,0,0*num)
            tdSql.query("select count(tbname),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(6,0,60*num)
            tdSql.query("select count(loc),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(7,0,60*num)
            tdSql.query("select count(t_int),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(8,0,60*num)
            tdSql.query("select count(t_bigint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(9,0,60*num)
            tdSql.query("select count(t_smallint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(t_tinyint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(1,0,60*num)
            tdSql.query("select count(t_int_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(2,0,60*num)
            tdSql.query("select count(t_bigint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(3,0,60*num)
            tdSql.query("select count(t_smallint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(4,0,60*num)
            tdSql.query("select count(t_tinyint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(5,0,60*num)
            tdSql.query("select count(t_float),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(6,0,60*num)
            tdSql.query("select count(t_double),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(7,0,60*num)
            tdSql.query("select count(t_bool),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(8,0,60*num)
            tdSql.query("select count(t_binary),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(9,0,60*num)
            tdSql.query("select count(t_nchar),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(t_ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(1,0,60*num)
            
            #window
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts),last(ts),last_row(ts),sum(cast(ts as int)),avg(cast(ts as int)),max(cast(ts as int)),min(cast(ts as int)) from {}.stable_0 partition by loc,tbname interval(1s) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts),last(ts),last_row(ts),sum(cast(ts as int)),avg(cast(ts as int)),max(cast(ts as int)),min(cast(ts as int)) from {}.stable_0 partition by loc,tbname interval(1a) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname interval(1s) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname interval(1a) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname state_window(ts_pk) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname session(ts,1s) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname session(ts,1a) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname event_window start with ts_pk >0 end with ts_pk <=10  order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname event_window start with ts_pk >0 end with ts_pk <=10  order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname count_window(10) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname count_window(10) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)

        table_list = ['stable_1_1','stable_2_2','stable_3_3','stable_4_4','stable_5_5','stable_6_6']
        for i in table_list:
            tdSql.query("select count(*),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,60*num)  
            
            tdSql.query("select count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(ts_pk),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(q_int),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bigint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_smallint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_tinyint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_int_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bigint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_smallint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_tinyint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_float),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_double),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bool),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_binary),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_nchar),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_int_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_bigint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_smallint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_tinyint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_float_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_double_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_bool_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_binary_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_nchar_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_ts_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(tbname),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,60*num)
    
        #window
            sql = "select _wstart,count(ts),tbname,first(ts),last(ts),last_row(ts),sum(cast(ts as int)),avg(cast(ts as int)),max(cast(ts as int)),min(cast(ts as int)) from {}.regular_table_0 partition by tbname,tbname interval(1s) order by _wstart,tbname".format(db)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,first(ts),last(ts),last_row(ts),sum(cast(ts as int)),avg(cast(ts as int)),max(cast(ts as int)),min(cast(ts as int)) from {}.regular_table_0 partition by tbname,tbname interval(1a) order by _wstart,tbname".format(db)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname interval(1s) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname interval(1a) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname state_window(ts_pk) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname session(ts,1s) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname session(ts,1a) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname event_window start with ts_pk >0 end with ts_pk <=10 order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname event_window start with ts_pk >0 end with ts_pk <=10 order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname count_window(10) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname count_window(10) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i)
            self.explain_sql_pass(sql)

        #group by tag + order by tag + tag-cast
        stable_list = ['stable_1','stable_2','stable_3','stable_4','stable_5','stable_6']
        for i in stable_list:
            tdSql.query("select count(*),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.checkData(2,0,60*num)
            tdSql.checkData(4,0,60*num)
            tdSql.checkData(6,0,60*num)
            tdSql.checkData(8,0,60*num)   
            
            tdSql.query("select count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(ts_pk),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(1,0,60*num)
            tdSql.query("select count(q_int),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(2,0,30*num)
            tdSql.query("select count(q_bigint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(3,0,30*num)
            tdSql.query("select count(q_smallint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts".format(db, i))
            tdSql.checkData(4,0,30*num)
            tdSql.query("select count(q_tinyint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(5,0,30*num)
            tdSql.query("select count(q_int_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(6,0,30*num)
            tdSql.query("select count(q_bigint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(7,0,30*num)
            tdSql.query("select count(q_smallint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(8,0,30*num)
            tdSql.query("select count(q_tinyint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(9,0,30*num)
            tdSql.query("select count(q_float),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_double),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(1,0,30*num)
            tdSql.query("select count(q_bool),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(2,0,30*num)
            tdSql.query("select count(q_binary),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(3,0,30*num)
            tdSql.query("select count(q_nchar),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(4,0,30*num)
            tdSql.query("select count(q_ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(5,0,30*num)
            tdSql.query("select count(q_int_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(6,0,0*num)
            tdSql.query("select count(q_bigint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(7,0,0*num)
            tdSql.query("select count(q_smallint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(8,0,0*num)
            tdSql.query("select count(q_tinyint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(9,0,0*num)
            tdSql.query("select count(q_float_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_double_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(1,0,0*num)
            tdSql.query("select count(q_bool_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(2,0,0*num)
            tdSql.query("select count(q_binary_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(3,0,0*num)
            tdSql.query("select count(q_nchar_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(4,0,0*num)
            tdSql.query("select count(q_ts_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(5,0,0*num)
            tdSql.query("select count(tbname),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(6,0,60*num)
            tdSql.query("select count(loc),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(7,0,60*num)
            tdSql.query("select count(t_int),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(8,0,60*num)
            tdSql.query("select count(t_bigint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(9,0,60*num)
            tdSql.query("select count(t_smallint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(t_tinyint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(1,0,60*num)
            tdSql.query("select count(t_int_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(2,0,60*num)
            tdSql.query("select count(t_bigint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(3,0,60*num)
            tdSql.query("select count(t_smallint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(4,0,60*num)
            tdSql.query("select count(t_tinyint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(5,0,60*num)
            tdSql.query("select count(t_float),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(6,0,60*num)
            tdSql.query("select count(t_double),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(7,0,60*num)
            tdSql.query("select count(t_bool),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(8,0,60*num)
            tdSql.query("select count(t_binary),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(9,0,60*num)
            tdSql.query("select count(t_nchar),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(t_ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} group by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(1,0,60*num)
            
            #window
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts),last(ts),last_row(ts),sum(cast(ts as int)),avg(cast(ts as int)),max(cast(ts as int)),min(cast(ts as int)) from {}.stable_0 partition by loc,tbname interval(1s) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts),last(ts),last_row(ts),sum(cast(ts as int)),avg(cast(ts as int)),max(cast(ts as int)),min(cast(ts as int)) from {}.stable_0 partition by loc,tbname interval(1a) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname interval(1s) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname interval(1a) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname state_window(ts_pk) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname session(ts,1s) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname session(ts,1a) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname event_window start with ts_pk >0 end with ts_pk <=10  order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname event_window start with ts_pk >0 end with ts_pk <=10  order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname count_window(10) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname count_window(10) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts   ".format(db, i)
            self.explain_sql_pass(sql)

        table_list = ['stable_1_1','stable_2_2','stable_3_3','stable_4_4','stable_5_5','stable_6_6']
        for i in table_list:
            tdSql.query("select count(*),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,60*num)  
            
            tdSql.query("select count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(ts_pk),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,60*num)
            tdSql.query("select count(q_int),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bigint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_smallint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_tinyint),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_int_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bigint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_smallint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_tinyint_unsigned),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_float),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_double),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_bool),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_binary),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_nchar),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,30*num)
            tdSql.query("select count(q_int_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_bigint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_smallint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_tinyint_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_float_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_double_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_bool_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_binary_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_nchar_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(q_ts_null),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i))
            tdSql.checkData(0,0,0*num)
            tdSql.query("select count(tbname),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname order by tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i))
            tdSql.checkData(0,0,60*num)
    
        #window
            sql = "select _wstart,count(ts),tbname,first(ts),last(ts),last_row(ts),sum(cast(ts as int)),avg(cast(ts as int)),max(cast(ts as int)),min(cast(ts as int)) from {}.regular_table_0 partition by tbname,tbname interval(1s) order by _wstart,tbname".format(db)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,first(ts),last(ts),last_row(ts),sum(cast(ts as int)),avg(cast(ts as int)),max(cast(ts as int)),min(cast(ts as int)) from {}.regular_table_0 partition by tbname,tbname interval(1a) order by _wstart,tbname".format(db)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname interval(1s) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname interval(1a) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname state_window(ts_pk) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname session(ts,1s) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname session(ts,1a) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname event_window start with ts_pk >0 end with ts_pk <=10 order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname event_window start with ts_pk >0 end with ts_pk <=10 order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts  ".format(db, i)
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname count_window(10) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i)
            self.explain_sql_pass(sql)
            sql = "select _wstart,count(ts),tbname,t_bool,t_int,t_nchar,t_float,t_ts,cast(t_bool as smallint),t_bigint+1,cast(t_binary as bigint),t_double-1,first(ts_pk),last(ts_pk),last_row(ts_pk),sum(cast(ts_pk as int)),avg(cast(ts_pk as int)),max(cast(ts_pk as int)),min(cast(ts_pk as int)) from {}.{} partition by loc,tbname count_window(10) order by _wstart,tbname,t_bool,t_int,t_nchar,t_float,t_ts ".format(db, i)
            self.explain_sql_pass(sql)

    def fun_pk_diff(self,db,replace_fun,replace_num):
        num_table_list1 = ['stable_1','stable_3','regular_table_1','regular_table_3','stable_2','stable_4','regular_table_2','regular_table_4']#,'stable_5','regular_table_5','stable_6','regular_table_6'
        for i in num_table_list1:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0_1 ".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0_1 order by ts".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0_1 order by ts desc".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)       
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            
            sql = "select {}(ts{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0_1 ".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select to_char(ts,'yyyy-mmdd-hh24miss'),{}(ts{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-0828-053320')
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0_1 order by ts".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0_1 order by ts desc".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select ts_pk,{}(ts{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            self.explain_sql_pass(sql)
            sql = "select ts_pk,{}(ts{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            self.explain_sql_pass(sql)

        table_list = ['stable_1','stable_2','stable_3','stable_4','regular_table_1','regular_table_2','regular_table_3','regular_table_4']#,'stable_5','stable_6','regular_table_5','regular_table_6']
        for i in table_list:
            
            sql = "select to_char(ts,'yyyy-mmdd-hh24miss'),{}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-0828-053320')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)

    def fun_pk_twa(self,db,replace_fun,replace_num):
        num_table_list1 = ['stable_1','stable_3','regular_table_1','regular_table_3','stable_2','stable_4','regular_table_2','regular_table_4']#,'stable_5','regular_table_5','stable_6','regular_table_6'
        for i in num_table_list1:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)       
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)

        table_list = ['stable_1','stable_2','stable_3','stable_4','regular_table_1','regular_table_2','regular_table_3','regular_table_4']#,'stable_5','stable_6','regular_table_5','regular_table_6']
        for i in table_list:           
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)

    def fun_pk_interp(self,db,replace_fun,replace_num):
        num_table_list1 = ['stable_1','stable_3','regular_table_1','regular_table_3','stable_2','stable_4','regular_table_2','regular_table_4','stable_5','regular_table_5','stable_6','regular_table_6']
        for i in num_table_list1:
            sql = "select _irowts,_isfilled,{}(cast(ts_pk{} as int)) from {}.{} range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(NULL) ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select _irowts,_isfilled,{}(q_int{}) from {}.stable_0 range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(NULL)  ".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select _irowts,_isfilled,{}(cast(ts_pk{} as int)) from {}.{} range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(LINEAR)  order by _irowts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select _irowts,_isfilled,{}(q_int{}) from {}.stable_0 range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(LINEAR)  order by _irowts".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select _irowts,_isfilled,{}(cast(ts_pk{} as int)) from {}.{} range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(PREV)  order by _irowts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select _irowts,_isfilled,{}(q_int{}) from {}.stable_0 range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(PREV)  order by _irowts desc".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(cast(ts_pk{} as int)) ts_pk,_irowts,_isfilled from {}.{} range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(VALUE,100)  order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)       
            sql = "select {}(cast(ts_pk{} as int)) ts_pk,_irowts,_isfilled from {}.{} range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(NEXT)  order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            
            sql = "select _irowts,_isfilled,{}(cast(ts_pk{} as int)) from {}.{} range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(PREV) ".format(replace_fun,replace_num,db, i)
            self.explain_sql_pass(sql)
            sql = "select _irowts,_isfilled,{}(q_int{}) from {}.stable_0 range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(PREV)  ".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select _irowts,_isfilled,{}(cast(ts_pk{} as int)) from {}.{} range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(NEXT)  order by _irowts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 00:00:00.000')
            self.explain_sql_pass(sql)
            sql = "select _irowts,_isfilled,{}(q_int{}) from {}.stable_0 range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(NEXT)  order by _irowts".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select _irowts,_isfilled,{}(cast(ts_pk{} as int)) from {}.{} range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(VALUE,100)  order by _irowts desc".format(replace_fun,replace_num,db, i)
            self.explain_sql_pass(sql)
            sql = "select _irowts,_isfilled,{}(q_int{}) from {}.stable_0 range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(VALUE_F,100)  order by _irowts desc".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(cast(ts_pk{} as int)) ts_pk,_irowts,_isfilled from {}.{} range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(LINEAR)  order by ts_pk".format(replace_fun,replace_num,db, i)
            self.explain_sql_pass(sql)
            sql = "select {}(cast(ts_pk{} as int)) ts_pk,_irowts,_isfilled from {}.{} range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(LINEAR)  order by ts_pk desc".format(replace_fun,replace_num,db, i)
            self.explain_sql_pass(sql)

        table_list = ['stable_1','stable_2','stable_3','stable_4','stable_5','stable_6','regular_table_1','regular_table_2','regular_table_3','regular_table_4','regular_table_5','regular_table_6']
        for i in table_list:
            
            sql = "select _irowts,_isfilled,{}(cast(ts_pk{} as int)) from {}.{} range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(LINEAR) ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-29 00:00:00.000')
            self.explain_sql_pass(sql)
            
            sql = "select _irowts,_isfilled,{}(cast(ts_pk{} as int)) from {}.{} range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(NEXT) order by _irowts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 00:00:00.000')
            self.explain_sql_pass(sql)
            sql = "select _irowts,_isfilled,{}(cast(ts_pk{} as int)) from {}.{} range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(PREV) order by _irowts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            
            sql = "select {}(cast(ts_pk{} as int)) ts_pk,_irowts,_isfilled from {}.{} range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(VALUE,10000) order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select {}(cast(ts_pk{} as int)) ts_pk,_irowts,_isfilled from {}.{} range('2021-08-28 00:00:00','2032-08-28 00:00:00') every(1d) fill(VALUE_F,-10000) order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)

    def fun_pk_unique(self,db,replace_fun,replace_num):
        num_table_list1 = ['stable_1','stable_3','regular_table_1','regular_table_3','stable_2','stable_4','regular_table_2','regular_table_4','stable_5','regular_table_5','stable_6','regular_table_6']
        for i in num_table_list1:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0 ".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0 order by ts".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0 order by ts desc".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)       
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            
            sql = "select {}(ts{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0 ".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 05:33:20.000')
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0 order by ts".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0 order by ts desc".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select ts_pk,{}(ts{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            self.explain_sql_pass(sql)
            sql = "select ts_pk,{}(ts{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            self.explain_sql_pass(sql)

        table_list = ['stable_1','stable_2','stable_3','stable_4','stable_5','stable_6','regular_table_1','regular_table_2','regular_table_3','regular_table_4','regular_table_5','regular_table_6']
        for i in table_list:
            
            sql = "select ts,{}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 05:33:20')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 05:33:20')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 05:33:20')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 05:33:20')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 05:33:20')
            self.explain_sql_pass(sql)

    def fun_pk_first(self,db,replace_fun,replace_num):
        num_table_list1 = ['stable_1','stable_3','regular_table_1','regular_table_3']
        for i in num_table_list1:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,16)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0 ".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,16)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0 order by ts".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,16)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0 order by ts desc".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,16)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,16)
            self.explain_sql_pass(sql)
        
        num_table_list2 = ['stable_2','stable_4','regular_table_2','regular_table_4']
        for i in num_table_list2:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,41)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,41)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,41)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,41)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,41)
            self.explain_sql_pass(sql)
                
        str_table_list1 = ['stable_5','regular_table_5']
        for i in str_table_list1:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,16)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,16)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,16)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,16)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,16)
            self.explain_sql_pass(sql)
        
        str_table_list2 = ['stable_6','regular_table_6']
        for i in str_table_list2:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'41')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'41')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'41')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'41')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'41')
            self.explain_sql_pass(sql)
            
        table_list = ['stable_1','stable_2','stable_3','stable_4','stable_5','stable_6','regular_table_1','regular_table_2','regular_table_3','regular_table_4','regular_table_5','regular_table_6']
        for i in table_list:
            
            sql = "select ts,{}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 05:33:20')
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,ts,{}(ts_pk{}) from {}.{} interval(1s)".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 05:33:20')
            self.explain_sql_pass(sql)
            sql = "select _wstart,ts,{}(ts_pk{}) from {}.{} interval(1a)".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 05:33:20')
            self.explain_sql_pass(sql)
            
            sql = "select _wstart,{}(ts{}) from {}.stable_0 interval(1s)".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select _wstart,{}(ts{}) from {}.stable_0 interval(1a)".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 05:33:20')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 05:33:20')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 05:33:20')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 05:33:20')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} group by tbname ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 05:33:20')
            self.explain_sql_pass(sql)

            sql = "select {}(ts{}) from {}.stable_0 group by tbname ".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)

    def fun_pk_last(self,db,replace_fun,replace_num): 
        self.fun_pk_last_init(self.database,'last','') 
        self.fun_pk_last_init(self.database,'last_row','') 
                
    def fun_pk_last_init(self,db,replace_fun,replace_num):
        num_table_list1 = ['stable_1','stable_3','regular_table_1','regular_table_3']
        for i in num_table_list1:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,25)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0 ".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            
            sql_compare1 = "select {}(ts) from {}.stable_0 order by ts desc limit 1".format(replace_fun,db)
            self.explain_sql_pass(sql_compare1)
            sql_compare = "select (ts) from {}.stable_0 order by ts desc limit 1".format(db)
            self.explain_sql_pass(sql_compare)
            sql_compare2 = "select (ts),max(cast (ts as bigint)) from {}.stable_0 ".format(db)
            self.explain_sql_pass(sql_compare2)
            
            sql = "select {}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,25)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0 order by ts".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,25)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0 order by ts desc".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,25)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,25)
            self.explain_sql_pass(sql)
        
        num_table_list2 = ['stable_2','stable_4','regular_table_2','regular_table_4']
        for i in num_table_list2:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,50)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,50)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,50)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,50)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,50)
            self.explain_sql_pass(sql)
                
        str_table_list1 = ['stable_5','regular_table_5']
        for i in str_table_list1:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'25')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'25')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'25')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'25')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'25')
            self.explain_sql_pass(sql)
                
        str_table_list1 = ['stable_6','regular_table_6']
        for i in str_table_list1:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'50')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'50')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'50')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'50')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'50')
            self.explain_sql_pass(sql)
            
        table_list = ['stable_1','regular_table_1','stable_2','regular_table_2','stable_3','regular_table_3','stable_4','regular_table_4','stable_5','regular_table_5','stable_6','regular_table_6']
        for i in table_list:
            sql = "select _wstart,ts,{}(ts_pk{}) from {}.{} interval(1s)".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 05:33:20.000')
            self.explain_sql_pass(sql)
            sql = "select _wstart,ts,{}(ts_pk{}) from {}.{} interval(1a)".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-08-28 05:33:20.000')
            self.explain_sql_pass(sql)

            sql = "select _wstart,{}(ts{}) from {}.stable_0 interval(1s)".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select _wstart,{}(ts{}) from {}.stable_0 interval(1a)".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
        
        table_list = ['stable_1','regular_table_1']
        for i in table_list:           
            sql_compare = "select {}(ts) from {}.{} order by ts desc limit 1".format(replace_fun,db, i)
            self.explain_sql_pass(sql_compare)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-10-23 22:40:00.011')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-10-23 22:40:00.011')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-10-23 22:40:00.011')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-10-23 22:40:00.011')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-10-23 22:40:00.011')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} group by tbname ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-10-23 22:40:00.011')
            self.explain_sql_pass(sql)
            
            sql = "select {}(ts{}) from {}.stable_0 group by tbname ".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
        
        table_list = ['stable_2','regular_table_2']
        for i in table_list:
            sql = "select ts,{}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-12-20 19:33:20.012')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-12-20 19:33:20.012')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-12-20 19:33:20.012')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-12-20 19:33:20.012')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-12-20 19:33:20.012')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} group by tbname ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-12-20 19:33:20.012')
            self.explain_sql_pass(sql)
            
        table_list = ['stable_3','regular_table_3']
        for i in table_list:
            sql = "select ts,{}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-02-16 16:26:40.013')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-02-16 16:26:40.013')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-02-16 16:26:40.013')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-02-16 16:26:40.013')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-02-16 16:26:40.013')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} group by tbname ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-02-16 16:26:40.013')
            self.explain_sql_pass(sql)

        table_list = ['stable_4','regular_table_4']
        for i in table_list:
            sql = "select ts,{}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2024-10-27 11:33:20.011')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2024-10-27 11:33:20.011')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2024-10-27 11:33:20.011')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2024-10-27 11:33:20.011')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2024-10-27 11:33:20.011')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} group by tbname ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2024-10-27 11:33:20.011')
            self.explain_sql_pass(sql)
        
        table_list = ['stable_5','regular_table_5']
        for i in table_list:
            sql = "select ts,{}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2053-05-05 03:33:20.011')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2053-05-05 03:33:20.011')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2053-05-05 03:33:20.011')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2053-05-05 03:33:20.011')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2053-05-05 03:33:20.011')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} group by tbname ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2053-05-05 03:33:20.011')
            self.explain_sql_pass(sql)  
        
        table_list = ['stable_6','regular_table_6']
        for i in table_list:
            sql = "select ts,{}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2338-07-17 19:33:20.011')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2338-07-17 19:33:20.011')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2338-07-17 19:33:20.011')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2338-07-17 19:33:20.011')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2338-07-17 19:33:20.011')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} group by tbname ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2338-07-17 19:33:20.011')
            self.explain_sql_pass(sql) 
        
        # TO DO
        # delete and insert        
    def fun_pk_last_delete(self,db,replace_fun,replace_num):
        num_table_list1 = ['stable_1','stable_3','regular_table_1','regular_table_3']
        for i in num_table_list1:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,23)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0 ".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,23)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0 order by ts".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,23)
            self.explain_sql_pass(sql)
            sql = "select {}(ts{}) from {}.stable_0 order by ts desc".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,23)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,23)
            self.explain_sql_pass(sql)
        
        num_table_list2 = ['stable_2','stable_4','regular_table_2','regular_table_4']
        for i in num_table_list2:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,48)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,48)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,48)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,48)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,48)
            self.explain_sql_pass(sql)
                
        str_table_list1 = ['stable_5','regular_table_5']
        for i in str_table_list1:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'23')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'23')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'23')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'23')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'23')
            self.explain_sql_pass(sql)
            
        str_table_list1 = ['stable_6','regular_table_6']
        for i in str_table_list1:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'48')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'48')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'48')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'48')
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'48')
            self.explain_sql_pass(sql)
            
        table_list = ['stable_1','regular_table_1','stable_2','regular_table_2','stable_3','regular_table_3','stable_4','regular_table_4','stable_5','regular_table_5','stable_6','regular_table_6']
        for i in table_list:
            sql = "select _wstart,ts,{}(ts_pk{}) from {}.{} interval(1s)".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select _wstart,ts,{}(ts_pk{}) from {}.{} interval(1a)".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)

            sql = "select _wstart,{}(ts{}) from {}.stable_0 interval(1s)".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
            sql = "select _wstart,{}(ts{}) from {}.stable_0 interval(1a)".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
        
        table_list = ['stable_1','regular_table_1']
        for i in table_list:
            sql = "select ts,{}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-10-21 15:06:40.011000')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-10-21 15:06:40.011000')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-10-21 15:06:40.011000')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-10-21 15:06:40.011000')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-10-21 15:06:40.011000')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} group by tbname ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-10-21 15:06:40.011000')
            self.explain_sql_pass(sql)
            
            sql = "select {}(ts{}) from {}.stable_0 group by tbname ".format(replace_fun,replace_num,db)
            self.explain_sql_pass(sql)
        
        table_list = ['stable_2','regular_table_2']
        for i in table_list:
            sql = "select ts,{}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-12-16 04:26:40.012')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-12-16 04:26:40.012')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-12-16 04:26:40.012')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-12-16 04:26:40.012')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-12-16 04:26:40.012')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} group by tbname ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2021-12-16 04:26:40.012')
            self.explain_sql_pass(sql)
            
        table_list = ['stable_3','regular_table_3']
        for i in table_list:
            sql = "select ts,{}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-02-09 17:46:40.013')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-02-09 17:46:40.013')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-02-09 17:46:40.013')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-02-09 17:46:40.013')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-02-09 17:46:40.013')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} group by tbname ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-02-09 17:46:40.013')
            self.explain_sql_pass(sql)

        table_list = ['stable_4','regular_table_4']
        for i in table_list:
            sql = "select ts,{}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-04-06 07:06:40.014')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-04-06 07:06:40.014')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-04-06 07:06:40.014')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-04-06 07:06:40.014')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-04-06 07:06:40.014')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} group by tbname ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-04-06 07:06:40.014')
            self.explain_sql_pass(sql)
        
        table_list = ['stable_5','regular_table_5']
        for i in table_list:
            sql = "select ts,{}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-05-31 20:26:40.015')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-05-31 20:26:40.015')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-05-31 20:26:40.015')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-05-31 20:26:40.015')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-05-31 20:26:40.015')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} group by tbname ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-05-31 20:26:40.015')
            self.explain_sql_pass(sql)  
        
        table_list = ['stable_6','regular_table_6']
        for i in table_list:
            sql = "select ts,{}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-07-26 09:46:40.016')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-07-26 09:46:40.016')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-07-26 09:46:40.016')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-07-26 09:46:40.016')
            self.explain_sql_pass(sql)
            sql = "select ts,{}(ts_pk{}) from {}.{} order by ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-07-26 09:46:40.016')
            self.explain_sql_pass(sql)
            
            sql = "select ts,{}(ts_pk{}) from {}.{} group by tbname ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            tdSql.checkData(0,0,'2022-07-26 09:46:40.016')
            self.explain_sql_pass(sql) 

    def fun_pk_num_agg(self,db,replace_fun,replace_num):
        num_table_list = ['stable_1','stable_2','stable_3','stable_4','regular_table_1','regular_table_2','regular_table_3','regular_table_4']
        for i in num_table_list:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
                
    def fun_pk_num_1(self,db,replace_fun,replace_num):
        num_table_list = ['stable_1','stable_2','stable_3','stable_4','regular_table_1','regular_table_2','regular_table_3','regular_table_4']
        for i in num_table_list:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts,ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts,ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)

    def fun_pk_str_1(self,db,replace_fun,replace_num):
        str_table_list = ['stable_5','stable_6','regular_table_5','regular_table_6']
        for i in str_table_list:
            sql = "select {}(ts_pk{}) from {}.{} ".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts,ts_pk".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)
            sql = "select {}(ts_pk{}) from {}.{} order by ts,ts_pk desc".format(replace_fun,replace_num,db, i)
            tdSql.query(sql)
            self.explain_sql_pass(sql)

    def query_pk_fun(self,database,num=1):
        self.fun_pk_num_1(self.database,'','') 
        self.fun_pk_num_agg(self.database,'count','') 
        self.fun_pk_num_agg(self.database,'sum','') 
        self.fun_pk_num_agg(self.database,'avg','') 
        
        self.fun_pk_num_1(self.database,'first','') 
        self.fun_pk_num_1(self.database,'last','') 
        self.fun_pk_num_1(self.database,'last_row','') 
        self.fun_pk_num_1(self.database,'max','') 
        self.fun_pk_num_1(self.database,'min','') 
        self.fun_pk_num_1(self.database,'mode','') 
        self.fun_pk_num_1(self.database,'unique','') 
        self.fun_pk_num_1(self.database,'sample',',10') 
        self.fun_pk_num_1(self.database,'top',',10') 
        self.fun_pk_num_1(self.database,'bottom',',10') 
        self.fun_pk_num_1(self.database,'tail',',10') 
        
        self.fun_pk_num_1(self.database,'diff','') 
        self.fun_pk_num_agg(self.database,'twa','') 
        
        self.fun_pk_num_1(self.database,'abs','') 
        self.fun_pk_num_1(self.database,'acos','') 
        self.fun_pk_num_1(self.database,'asin','') 
        self.fun_pk_num_1(self.database,'atan','') 
        self.fun_pk_num_1(self.database,'ceil','') 
        self.fun_pk_num_1(self.database,'cos','') 
        self.fun_pk_num_1(self.database,'floor','') 
        self.fun_pk_num_1(self.database,'log','') 
        self.fun_pk_num_1(self.database,'pow',',2') 
        self.fun_pk_num_1(self.database,'round','') 
        self.fun_pk_num_1(self.database,'sin','') 
        self.fun_pk_num_1(self.database,'sqrt','') 
        self.fun_pk_num_1(self.database,'tan','') 
        
        self.fun_pk_str_1(self.database,'char_length','') 
        self.fun_pk_str_1(self.database,'concat',',ts_pk') 
        self.fun_pk_str_1(self.database,'length','') 
        self.fun_pk_str_1(self.database,'lower','') 
        self.fun_pk_str_1(self.database,'ltrim','') 
        self.fun_pk_str_1(self.database,'rtrim','') 
        self.fun_pk_str_1(self.database,'substr',',1') 
        self.fun_pk_str_1(self.database,'upper','') 

    def test_primary_ts_base(self):
        """summary: xxx

        description: xxx

        Since: xxx

        Labels: xxx

        Jira: xxx

        Catalog:
            - xxx:xxx

        History:
            - xxx
            - xxx

        """

        startTime = time.time() 
        self.case_init()
        self.dropandcreateDB_primary_key(self.database, 1 , 1 ,'yes','yes','no')

        self.query_pk(self.database,1) 
        
        endTime = time.time()
        print("total time %ds" % (endTime - startTime))

        #tdSql.close()
        tdLog.success(f"{__file__} successfully executed")
